<script type="text/javascript">
	//List Configuration
	$j("#list_medic").jqGrid({
		url:'medic/list',
		datatype:'json',
		mtype:'POST',
		colNames:[
		  		'Apellido', 
		  		'Nombre', 
		  		'Tipo de Documento', 
		  		'N° Documento', 
		  		'Fecha de Nacimiento', 
		  		'Sexo', 
		  		'Direccion', 
		  		'Telefono', 
		  		'Celular', 
		  		'Correo Electronico', 
		  		'Ciudad', 
		  		'Especialidad'
		  		],
		colModel:[
				  {
					  name:'surname',
					  index:'surname',
					  width:30,
					  editable: true
				  },
				  {
					  name:'name', 
					  index:'name', 
					  width:30, 
					  editable: true
				  },
				  {
					  name:'doctype', 
					  index:'doctype',
					  search:false, 
					  width:50, 
					  editable: true, 
					  hidden: true, 
					  editrules: {edithidden:true},
					  edittype: 'select',
					  editoptions:{
						   value:{ 
						  	<?php
						  		 $doctypes = Helper_Service::factory("identitycard")->getList();
						  		 $count = count($doctypes);
						  		 
						  		 $i=0;
						  		 foreach($doctypes as $id=>$description){
						  		 	echo $id.":'".$description[0]."'";
						  		 	if (($i+1) < $count) echo ",";
						  		 	else echo "";
						  		 	$i++;
						  		 }
						  	?>
					  		}
				  	  }
				  },
				  {
					  name:'identity_card_number', 
					  index:'identity_card_number',
					  search:false, 
					  width:50, 
					  editable: true, 
					  hidden: true, 
					  editrules: {edithidden:true},
					  align:"right"
				  },
				  {
					  name:'birthdate',
					  index: 'birthdate',
					  search:false,
					  width: 30,
					  editable: true,
					  hidden: true,
					  editrules: {edithidden:true}
				  },
				  {
					  name: 'sex',
					  index: 'sex',
					  width: 10,
					  search:false,
					  editable: true,
					  hidden: true,
					  editrules: {edithidden:true},
					  edittype: 'select',
					  editoptions: {value:"M:Masculino;F:Femenino"}
				  },
				  {
					  name: 'address',
					  index: 'address',
					  search:false,
					  width: 60,
					  editable: true,
					  hidden: true,
					  editrules: {edithidden:true}
				  },
				  {
					  name: 'phone',
					  index: 'phone',
					  search:false,
					  width: 60,
					  editable: true,
					  hidden: true,
					  editrules: {edithidden:true},
					  align:"right"
				  },
				  {
					  name: 'cel',
					  index: 'cel',
					  search:false,
					  width: 60,
					  editable: true,
					  hidden: true,
					  editrules: {edithidden:true},
					  align:"right"
				  },
				  {
			          name:'email', 
			          index:'email', 
			          width:80, 
			          editable: true
			      },
			      {
			    	  name: 'city',
					  index: 'city',
					  search:false,
					  width: 30,
					  editable: true,
					  hidden: true,
					  editrules: {edithidden:true}
				  },
		          {
			          name:'specialty', 
			          index:'specialty', 
			          width:80, 
			          editable: true
			      }
		],
		pager :'#gridpager_medic',
		loadtext: 'Cargando Lista de Médicos ...',
		rowNum : 10,
		rowList :[10],
		sortname :'surname',
		sortorder :'asc',
		autowidth :true,
		viewrecords :true,
		onSelectRow :function(id){},
		editurl:'medic/save',
		scrollOffset:0 
		//caption:'Medicos'
	});

	$j("#list_medic").setGridHeight(220);
	
	//Form editing
	$j("#list_medic").jqGrid(
			'navGrid',
			'#gridpager_medic',
			{
				edit:true,
				add:true,
				del:true,
				search:true
			},
			{
				width: 400,
				height: 280,
				closeAfterEdit: true,
				editCaption: "Modificar Médico",
				afterShowForm:function(){
					DateControl.createDatePicker('#birthdate','<?php echo Helper_Date::now();?>', 'Regressive');
				} 
			},
			{
				width: 400,
				height: 280,
				closeAfterAdd: true,
				addCaption: "Nuevo Médico",
				afterShowForm:function(){
					DateControl.createDatePicker('#birthdate','<?php echo Helper_Date::now();?>', 'Regressive');
				}
			},
			{
				msg: "¿Desea eliminar al médico seleccionado?",
				caption: "Eliminar Médico",
				width:300
			},
			{
				sopt:['eq','bw','ew','cn']
			}
	);
</script>